﻿@using CRM.Admin.Areas.Customer.Controllers
@using CRM.Admin.Contracts.Dto.Sys
@{
    ViewBag.Title = "CustomerInfoAdd";
}
@section head
{
<link href="@Url.Content("~/ScriptPlugin/easyui/themes/gray/easyui.css")" rel="stylesheet" />
<link href="@Url.Content("~/ScriptPlugin/easyui/themes/icon.css")" rel="stylesheet" />
<script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/jquery.easyui.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/ScriptPlugin/easyui/locale/easyui-lang-zh_CN.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.DataGrid.Filter.js")"></script>
<script src="@Url.Content("~/ScriptPlugin/WdatePicker/js/WdatePicker.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/form2json.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.min.js")"></script>
    <script type="text/javascript" src="@Url.Content("~/Scripts/jquery.validate.extended.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/picdata.js")"></script>
<script src="@Url.Content("~/Scripts/jquery.linq.min.js")"></script>
<script type="text/javascript" src="@Url.Content("~/ScriptPlugin/webuploader/webuploader.js")"></script>
<script type="text/javascript" src="@Url.Content("~/Scripts/KingsSharp.Uploader.js")"></script>
    <style type="text/css">
        .uploader {
            text-align: center;
            float:left;width: 50px;
            height: 32px;line-height: 32px;
            color: blue;
            }
        .uploader-show {
            float:left;width: 70%;
            line-height: 32px;
        }
        .uploader-show a {
            margin-right: 5px;
            color:green;
        }
        .uploader-show img {
            width: 100%;height:32px;
        }
        .uploader-show img.mulit {
            width: 32px;height:32px;
            padding-right: 5px;
        }
    </style>
}
<form action="" id="customerForm">
    <div class="content-form" id="content-form">
    <table class="content-table">
    <tr>
        <th><span>顾客名称</span></th>
        <td>
            <input type="text" maxlength="50" data-valid="required" id="Name" name="Name"/>
        </td>
        <th><span>顾客简称</span></th>
        <td>
            <input type="text" maxlength="50" data-valid="required" id="ShortName" name="ShortName" />
        </td>
        <th>顾客编码</th>
        <td>
            <input type="text" maxlength="50" disabled="disabled" id="Code" name="Code" placeholder="自动生成" />
        </td>
        <th>销售系统编码</th>
        <td>
            <input type="text" maxlength="50" id="SaleSysCode" name="SaleSysCode" />
        </td>
    </tr>
    <tr id="datapicke">
        <th><span>注册省</span></th>
        <td>
            <select data-picke="1" id="ProvinceCode" name="ProvinceCode" data-valid="required"></select>
            <input type="hidden" id="Province" name="Province"/>
        </td>
        <th><span>注册市</span></th>
        <td>
            <select data-picke="2" id="CityCode" name="CityCode" data-valid="required"></select>
            <input type="hidden" id="City" name="City"/>
        </td>
        <th><span>注册区</span></th>
        <td>
            <select data-picke="3" id="BoroughCode" name="BoroughCode"></select>
            <input type="hidden" id="Borough" name="Borough"/>
        </td>
        <th><span>邮政编码</span></th>
        <td>
            <input type="text" maxlength="50" id="PostCode" name="PostCode" data-valid="required"/>
        </td>
    </tr>
        <tr>
            <th><span>注册地址</span></th>
            <td colspan="7">
                <input type="text" maxlength="500" id="AddressDescription" name="AddressDescription" data-valid="required"/>
            </td>
        <tr id="datapicke1">
            <th>省</th>
            <td>
                <select data-picke="1" id="ProvinceCode1" name="ProvinceCode1"></select>
                <input type="hidden" id="Province1" name="Province1" />
            </td>
            <th>市</th>
            <td>
                <select data-picke="2" id="CityCode1" name="CityCode1"></select>
                <input type="hidden" id="City1" name="City1" />
            </td>
            <th>区</th>
            <td>
                <select data-picke="3" id="BoroughCode1" name="BoroughCode1"></select>
                <input type="hidden" id="Borough1" name="Borough1" />
            </td>
        <tr>
            <th>地址</th>
            <td colspan="7">
                <input type="text" maxlength="500" id="AddressDescription1" name="AddressDescription1" />
            </td>
        </tr>

    <tr>
        <th>企业规模/年经营额</th>
        <td>
            <input type="text" maxlength="20" id="Scale" name="Scale" />
        </td>
        <th><span>主营业务</span></th>
        <td>
            <input type="text" maxlength="20" id="Business" name="Business" data-valid="required"/>
        </td>
        <th><span>所属行业</span></th>
        <td>
            <select id="Industry" name="Industry" data-valid="required" >
                <option></option>
                @{
                    List<DictionaryDto> lbdtos = new List<DictionaryDto>();
                    lbdtos = (List<DictionaryDto>)ViewData[CustomerInfoController.DicCatalogType.KHHY];
                    foreach (var dto in lbdtos)
                    {
                        <option value="@dto.Name">@dto.Name</option>
                    }
                }
            </select>
        </td>
        <th>资信情况</th>
        <td>
            <input type="text" maxlength="20" id="CreditInfo" name="CreditInfo" />
        </td>
    </tr>
        <tr>
            <th><span>法人代表</span></th>
            <td>
                <input type="text" maxlength="20" id="LegalMan" name="LegalMan" data-valid="required"/>
            </td>
            <th>顾客类别</th>
            <td>
                <select id="Type" name="Type">
                    <option></option>
                    @{
                        lbdtos = (List<DictionaryDto>) ViewData[CustomerInfoController.DicCatalogType.KHLB];
                        foreach (var dto in lbdtos)
                        {
                            <option value="@dto.Name">@dto.Name</option>
                        }
                    }
                </select>
            </td>
            <th>与我公司合作状态</th>
            <td>
                <input type="text" id="CooperationState" name="CooperationState"/>
            </td>
            <th></th>
            <td>
                
            </td>
        </tr>
    <tr>
        <th>组织机构代码</th>
        <td>
            <input type="text" maxlength="20" id="OrganizationCode" name="OrganizationCode" />
        </td>
        <th>
            组织机构代证书
        </th>
        <td>
            <input type="hidden" id="OrganizationImageUrl" name="OrganizationImageUrl" />
            <div id="picker" class="uploader">
                上传
            </div>
            <div class="uploader-show">

            </div>
        </td>
        <th>税务登记号</th>
        <td>
            <input type="text" maxlength="20" id="TaxRegistrationCode" name="TaxRegistrationCode" />
        </td>
        <th>税务登记证证件</th>
        <td>
            <input type="hidden" id="TaxRegistrationImageUrl" name="TaxRegistrationImageUrl"/>
            <div id="picker1" class="uploader">
                上传
            </div>
            <div class="uploader-show">
                
            </div>
        </td>
    </tr>
        <tr>
            <th>营业执照</th>
            <td colspan="3">
                <input type="hidden" id="LicenseImageUrl" name="LicenseImageUrl"/>
                <div id="picker2" class="uploader">
                    上传
                </div>
                <div class="uploader-show" data-mulit="true">

                </div>
            </td>
            <th>银行资信证明</th>
            <td colspan="3">
                <input type="hidden" id="BankLicenseImageUrl" name="BankLicenseImageUrl"/>
                <div id="picker3" class="uploader">
                    上传
                </div>
                <div class="uploader-show" data-mulit="true">

                </div>
            </td>
        </tr>
        <tr>
            <th>开户银行</th>
            <td>
                <input type="text" maxlength="20" id="TicketBank" name="TicketBank" />
            </td>
            <th>开户账号</th>
            <td>
                <input type="text" maxlength="20" id="TicketBankAccount" name="TicketBankAccount" />
            </td>
            <th>开户信息附件</th>
            <td colspan="3">
                <input type="hidden" id="TicketAttachment" name="TicketAttachment" />
                <div id="picker4" class="uploader" data-type="file">
                    上传
                </div>
                <div class="uploader-show" data-mulit="true">

                </div>
            </td>
        </tr>
    @*<tr>
        <th>顾客简介</th>
        <td colspan="7">
            <textarea rows="4" id="Profiles" name="Profiles"></textarea>
        </td>
    </tr>*@
        @*<tr>
            <th>顾客简介（附件）</th>
            <td colspan="7">
                <input type="hidden" id="ProfilesAttachment" name="ProfilesAttachment" />
                <div id="picker5" class="uploader" data-type="file">
                    上传
                </div>
                <div class="uploader-show" data-mulit="true">

                </div>
            </td>
        </tr>*@
    <tr>
        <th>关联顾客名称</th>
        <td>
            <input type="text" readonly="readonly" onclick="getParent()" maxlength="20" id="ParentCustomer" name="ParentCustomer" class="p-icon-right p-icon-customer" />
            <input type="hidden" id="ParentId" name="ParentId" />
        </td>
        <th>顾客信用评价</th>
        <td>
            <select id="CreditRatings" name="CreditRatings">
                <option></option>
                @{
                    lbdtos = (List<DictionaryDto>) ViewData[CustomerInfoController.DicCatalogType.KHXYPJ];
                    foreach (var dto in lbdtos)
                    {
                        <option value="@dto.Name">@dto.Name</option>
                    }
                }
            </select>
        </td>
        <th>顾客年度协议完成情况</th>
         <td colspan="3">
            <input type="text" maxlength="20" id="AgreementFilishProfiles" name="AgreementFilishProfiles" />
         </td>
         </tr>
         <tr>
            <th>潜在顾客需求</th>
            <td colspan="7">
                <textarea rows="4" id="Demand" name="Demand"></textarea>
            </td>
        </tr>
        <tr>
            <th>潜在顾客需求（附件）</th>
            <td colspan="7">
                <input type="hidden" id="DemandFilePath" name="DemandFilePath" />
                <div id="picker6" class="uploader" data-type="file">
                    上传
                </div>
                <div class="uploader-show">

                </div>
            </td>
        </tr>
    <tr>
        <th>备注</th>
        <td colspan="7">
            <input type="text" maxlength="500" id="Remark" name="Remark" />
        </td>
    </tr>
    </table>
  </div>
</form>
@section foot
{
    <script type="text/javascript">
    function SaveData(index) {
        if ($("#customerForm").valid()) {

            $("#datapicke").find("select").each(function () {
                    var tx = $(this).find("option:selected").text();
                    $(this).parent().find("input[type='hidden']").val(tx);
            });
           
            var dto = $("#customerForm").serializeJson();
            //dto.LinkMans = $("#linkmanGrid").datagrid('getRows');
            //dto.CustomerNatures = $("#natureGrid").datagrid('getRows');
            K.AjaxJson("@Url.Content("~/Customer/CustomerInfo/CustomerInsert")", dto, function (result) {
                parent.K.layer.callback(index, result, dto);
                parent.K.layer.close(index);
            });
        }
    }

    K.PickeInit("datapicke");
    K.PickeInit("datapicke1");



    </script>

    <script type="text/javascript">
        
        function getParent()
        {
            K.layer.iframe({
                title: "顾客选择",
                initfull: false,
                content: "@Url.Content("~/Customer/CustomerInfo/CustomerCheck")",
                area: ["60%", "60%"],
                callback: function (checkRows) {
                    if (checkRows && checkRows.length > 0) {
                        $("#ParentCustomer").val(checkRows[0].Name);
                        $("#ParentId").val(checkRows[0].Id);
                    }
                }
            });
        }

        var uploaders = [];
        $(".uploader").each(function() {
            var that = $(this);
            var fileType = $(this).attr("data-type");
            var imgshow = that.parent().find(".uploader-show");
            var urlhidden = that.parent().find("input[type='hidden']");
            var pickid = "#" + that.prop("id");
            var ismulit = false;
            var fileInputName = "file";
            if (urlhidden) {
                fileInputName = urlhidden.prop("name");
            }
            if (imgshow.attr("data-mulit")) {
                ismulit = true;
            }

            var parameter = {
                swf: '@Url.Content("~/ScriptPlugin/webuploader/Uploader.swf")',
                server: '@Url.Content("~/Customer/CustomerInfo/UploaderProcess")',
                pick: {
                    id: pickid,
                    multiple: ismulit
                },
                resize: false,
                auto: true,
                fileVal: fileInputName
            };
            var eventer = {
                fileQueued: function(file) {
                    if (fileType && fileType === "file") {
                        if (ismulit) {
                            imgshow.append("（<a>" + file.name + "</a>）");
                        } else {
                            imgshow.html("（<a>" + file.name + "</a>）");
                        }
                    } else {
                        uploader.makeThumb(file, function(error, ret) {
                            if (error) {
                                imgshow.html("预览错误");
                            } else {
                                if (ismulit) {
                                    imgshow.append("<img src=\"" + ret + "\" class=\"mulit\" />");
                                } else {
                                    imgshow.html("<img src=\"" + ret + "\" />");
                                }
                            }
                        });
                    }
                },
                uploadSuccess: function(file, response) {
                    if (response.Filish) {
                        if (ismulit) {
                            var oldval = urlhidden.val();
                            if (oldval != "") {
                                oldval += ",";
                            }
                            urlhidden.val(oldval + response.Path);
                        } else {
                            urlhidden.val(response.Path);
                        }
                    }
                },
                uploadError: function() {
                    K.Alert("上传出错");
                }
            };
            if (fileType && fileType === "file") {
                var uploader = new K.Uploader().createFile(parameter, eventer);
                uploaders.push(uploader);
            } else {
                var uploader = new K.Uploader().createImage(parameter, eventer);
                uploaders.push(uploader);
            }

        });
    </script>
}